<?php
/**
 * Created by PhpStorm.
 * User: Eric
 * Date: 2021/10/24
 * Time: 13:43
 */

namespace app\admin\controller;


use app\model\Setting;
use think\facade\Db;
use think\Request;
use think\facade\Filesystem;
class Detail extends AdminAuth
{
    /**
     * 产品详情
     */
    public function index(Request $request) {
        $data = Setting::homeDetail('detail');
        $data['img'] =  $request->domain(true).$data['img'];
        return $this -> result(compact('data'));
    }
    public function notice(Request $request) {
        $notice = $request->post('notice');
       Db::name('setting') -> where('page','detail')->update(['notice' => $notice]);
        return $this -> result();
    }
    /**
     * @param $page
     * @param $slogan
     * @desc  设置首页标语
     */
    public function detailSlogan(Request $request) {
        $slogan = $request -> get('slogan');
        $slogan = trim($slogan);
        Db::name('setting')->where('page','detail')-> update(['slogan' => $slogan]);
        return $this->result(['slogan' => $slogan]);
    }

    /**
     * @param Request $request
     * @desc 上创首页主图
     */
    public function detailImg(Request $request) {
        $file = $request -> file('file');
        $path = Filesystem::disk('public')->putFile( 'detailPic', $file);
        $path = '/storage/'.$path;
        Db::name('setting')->where('page','detail')-> update(['img' => $path]);
        $path = $request->domain(true).$path;
        return $this->result(compact('path'));
    }
}